package com.wechat.servlet;

import com.wechat.DAO.DaoImpl.UserInfoDAOIpml;
import com.wechat.DAO.UserInfoDAO;
import com.wechat.servlet.Utils.Base64Decoder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class InfoServlet extends HttpServlet {


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserInfoDAO infoDAO = new UserInfoDAOIpml();
        if (request.getParameter("username") == null) {
            return;
        }
        String username = null;
        String nickname = null;
        String sex = null;
        String country = null;
        String province = null;
        String city = null;
        String HPUrl = null;
        try {
            String username64 = request.getParameter("username");
            String nickname64 = request.getParameter("nickname");
            String sex64 = request.getParameter("sex");
            String country64 = request.getParameter("country");
            String province64 = request.getParameter("province");
            String city64 = request.getParameter("city");
            System.out.println(username64+"  "+nickname64+"  "+sex64+"  "+country64+"  "+province64+"  "+city64);
            HPUrl = request.getParameter("HPUrl");
            username = Base64Decoder.decode(username64);
            nickname = Base64Decoder.decode(nickname64);
            sex = Base64Decoder.decode(sex64);
            country = Base64Decoder.decode(country64);
            province = Base64Decoder.decode(province64);
            city = Base64Decoder.decode(city64);
            infoDAO.add(username, nickname, sex, country, province, city, HPUrl);
            response.getWriter().write("success");
            System.out.println("服务器成功相应：success");
        } catch (Exception e) {
            System.out.println("提交内容不完整");
            e.printStackTrace();
        }
        System.out.println(username+"  "+nickname+"  "+sex+"  "+country+"  "+province+"  "+city+"  "+HPUrl);
    }
}
